home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / gcc / ppc-mos-gcc.lha / info / gcc.info-10 (.txt) < prev    next >
GNU Info File  |  2002-06-18  |  43KB  |  808 lines

  1. This is Info file gcc.info, produced by Makeinfo version 1.68 from the
  2. input file ./gcc.texi.
  3. INFO-DIR-SECTION Programming
  4. START-INFO-DIR-ENTRY
  5. * gcc: (gcc).                  The GNU Compiler Collection.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the use and the internals of the GNU compiler.
  8.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  9. Boston, MA 02111-1307 USA
  10.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  11. 1999, 2000 Free Software Foundation, Inc.
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided also
  17. that the sections entitled "GNU General Public License" and "Funding
  18. for Free Software" are included exactly as in the original, and
  19. provided that the entire resulting derived work is distributed under
  20. the terms of a permission notice identical to this one.
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that the sections entitled "GNU General Public
  24. License" and "Funding for Free Software", and this permission notice,
  25. may be included in translations approved by the Free Software Foundation
  26. instead of in the original English.
  27. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  28. Arrays of Variable Length
  29. =========================
  30.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  31. are declared like any other automatic arrays, but with a length that is
  32. not a constant expression.  The storage is allocated at the point of
  33. declaration and deallocated when the brace-level is exited.  For
  34. example:
  35.      FILE *
  36.      concat_fopen (char *s1, char *s2, char *mode)
  37.      {
  38.        char str[strlen (s1) + strlen (s2) + 1];
  39.        strcpy (str, s1);
  40.        strcat (str, s2);
  41.        return fopen (str, mode);
  42.      }
  43.    Jumping or breaking out of the scope of the array name deallocates
  44. the storage.  Jumping into the scope is not allowed; you get an error
  45. message for it.
  46.    You can use the function `alloca' to get an effect much like
  47. variable-length arrays.  The function `alloca' is available in many
  48. other C implementations (but not in all).  On the other hand,
  49. variable-length arrays are more elegant.
  50.    There are other differences between these two methods.  Space
  51. allocated with `alloca' exists until the containing *function* returns.
  52. The space for a variable-length array is deallocated as soon as the
  53. array name's scope ends.  (If you use both variable-length arrays and
  54. `alloca' in the same function, deallocation of a variable-length array
  55. will also deallocate anything more recently allocated with `alloca'.)
  56.    You can also use variable-length arrays as arguments to functions:
  57.      struct entry
  58.      tester (int len, char data[len][len])
  59.      {
  60.        ...
  61.      }
  62.    The length of an array is computed once when the storage is allocated
  63. and is remembered for the scope of the array in case you access it with
  64. `sizeof'.
  65.    If you want to pass the array first and the length afterward, you can
  66. use a forward declaration in the parameter list--another GNU extension.
  67.      struct entry
  68.      tester (int len; char data[len][len], int len)
  69.      {
  70.        ...
  71.      }
  72.    The `int len' before the semicolon is a "parameter forward
  73. declaration", and it serves the purpose of making the name `len' known
  74. when the declaration of `data' is parsed.
  75.    You can write any number of such parameter forward declarations in
  76. the parameter list.  They can be separated by commas or semicolons, but
  77. the last one must end with a semicolon, which is followed by the "real"
  78. parameter declarations.  Each forward declaration must match a "real"
  79. declaration in parameter name and data type.
  80. File: gcc.info,  Node: Macro Varargs,  Next: Subscripting,  Prev: Variable Length,  Up: C Extensions
  81. Macros with Variable Numbers of Arguments
  82. =========================================
  83.    In GNU C, a macro can accept a variable number of arguments, much as
  84. a function can.  The syntax for defining the macro looks much like that
  85. used for a function.  Here is an example:
  86.      #define eprintf(format, args...)  \
  87.       fprintf (stderr, format , ## args)
  88.    Here `args' is a "rest argument": it takes in zero or more
  89. arguments, as many as the call contains.  All of them plus the commas
  90. between them form the value of `args', which is substituted into the
  91. macro body where `args' is used.  Thus, we have this expansion:
  92.      eprintf ("%s:%d: ", input_file_name, line_number)
  93.      ==>
  94.      fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  95. Note that the comma after the string constant comes from the definition
  96. of `eprintf', whereas the last comma comes from the value of `args'.
  97.    The reason for using `##' is to handle the case when `args' matches
  98. no arguments at all.  In this case, `args' has an empty value.  In this
  99. case, the second comma in the definition becomes an embarrassment: if
  100. it got through to the expansion of the macro, we would get something
  101. like this:
  102.      fprintf (stderr, "success!\n" , )
  103. which is invalid C syntax.  `##' gets rid of the comma, so we get the
  104. following instead:
  105.      fprintf (stderr, "success!\n")
  106.    This is a special feature of the GNU C preprocessor: `##' before a
  107. rest argument that is empty discards the preceding sequence of
  108. non-whitespace characters from the macro definition.  (If another macro
  109. argument precedes, none of it is discarded.)
  110.    It might be better to discard the last preprocessor token instead of
  111. the last preceding sequence of non-whitespace characters; in fact, we
  112. may someday change this feature to do so.  We advise you to write the
  113. macro definition so that the preceding sequence of non-whitespace
  114. characters is just a single token, so that the meaning will not change
  115. if we change the definition of this feature.
  116. File: gcc.info,  Node: Subscripting,  Next: Pointer Arith,  Prev: Macro Varargs,  Up: C Extensions
  117. Non-Lvalue Arrays May Have Subscripts
  118. =====================================
  119.    Subscripting is allowed on arrays that are not lvalues, even though
  120. the unary `&' operator is not.  For example, this is valid in GNU C
  121. though not valid in other C dialects:
  122.      struct foo {int a[4];};
  123.      
  124.      struct foo f();
  125.      
  126.      bar (int index)
  127.      {
  128.        return f().a[index];
  129.      }
  130. File: gcc.info,  Node: Pointer Arith,  Next: Initializers,  Prev: Subscripting,  Up: C Extensions
  131. Arithmetic on `void'- and Function-Pointers
  132. ===========================================
  133.    In GNU C, addition and subtraction operations are supported on
  134. pointers to `void' and on pointers to functions.  This is done by
  135. treating the size of a `void' or of a function as 1.
  136.    A consequence of this is that `sizeof' is also allowed on `void' and
  137. on function types, and returns 1.
  138.    The option `-Wpointer-arith' requests a warning if these extensions
  139. are used.
  140. File: gcc.info,  Node: Initializers,  Next: Constructors,  Prev: Pointer Arith,  Up: C Extensions
  141. Non-Constant Initializers
  142. =========================
  143.    As in standard C++, the elements of an aggregate initializer for an
  144. automatic variable are not required to be constant expressions in GNU C.
  145. Here is an example of an initializer with run-time varying elements:
  146.      foo (float f, float g)
  147.      {
  148.        float beat_freqs[2] = { f-g, f+g };
  149.        ...
  150.      }
  151. File: gcc.info,  Node: Constructors,  Next: Labeled Elements,  Prev: Initializers,  Up: C Extensions
  152. Constructor Expressions
  153. =======================
  154.    GNU C supports constructor expressions.  A constructor looks like a
  155. cast containing an initializer.  Its value is an object of the type
  156. specified in the cast, containing the elements specified in the
  157. initializer.
  158.    Usually, the specified type is a structure.  Assume that `struct
  159. foo' and `structure' are declared as shown:
  160.      struct foo {int a; char b[2];} structure;
  161. Here is an example of constructing a `struct foo' with a constructor:
  162.      structure = ((struct foo) {x + y, 'a', 0});
  163. This is equivalent to writing the following:
  164.      {
  165.        struct foo temp = {x + y, 'a', 0};
  166.        structure = temp;
  167.      }
  168.    You can also construct an array.  If all the elements of the
  169. constructor are (made up of) simple constant expressions, suitable for
  170. use in initializers, then the constructor is an lvalue and can be
  171. coerced to a pointer to its first element, as shown here:
  172.      char **foo = (char *[]) { "x", "y", "z" };
  173.    Array constructors whose elements are not simple constants are not
  174. very useful, because the constructor is not an lvalue.  There are only
  175. two valid ways to use it: to subscript it, or initialize an array
  176. variable with it.  The former is probably slower than a `switch'
  177. statement, while the latter does the same thing an ordinary C
  178. initializer would do.  Here is an example of subscripting an array
  179. constructor:
  180.      output = ((int[]) { 2, x, 28 }) [input];
  181.    Constructor expressions for scalar types and union types are is also
  182. allowed, but then the constructor expression is equivalent to a cast.
  183. File: gcc.info,  Node: Labeled Elements,  Next: Cast to Union,  Prev: Constructors,  Up: C Extensions
  184. Labeled Elements in Initializers
  185. ================================
  186.    Standard C requires the elements of an initializer to appear in a
  187. fixed order, the same as the order of the elements in the array or
  188. structure being initialized.
  189.    In GNU C you can give the elements in any order, specifying the array
  190. indices or structure field names they apply to.  This extension is not
  191. implemented in GNU C++.
  192.    To specify an array index, write `[INDEX]' or `[INDEX] =' before the
  193. element value.  For example,
  194.      int a[6] = { [4] 29, [2] = 15 };
  195. is equivalent to
  196.      int a[6] = { 0, 0, 15, 0, 29, 0 };
  197. The index values must be constant expressions, even if the array being
  198. initialized is automatic.
  199.    To initialize a range of elements to the same value, write `[FIRST
  200. ... LAST] = VALUE'.  For example,
  201.      int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
  202. Note that the length of the array is the highest value specified plus
  203.    In a structure initializer, specify the name of a field to initialize
  204. with `FIELDNAME:' before the element value.  For example, given the
  205. following structure,
  206.      struct point { int x, y; };
  207. the following initialization
  208.      struct point p = { y: yvalue, x: xvalue };
  209. is equivalent to
  210.      struct point p = { xvalue, yvalue };
  211.    Another syntax which has the same meaning is `.FIELDNAME ='., as
  212. shown here:
  213.      struct point p = { .y = yvalue, .x = xvalue };
  214.    You can also use an element label (with either the colon syntax or
  215. the period-equal syntax) when initializing a union, to specify which
  216. element of the union should be used.  For example,
  217.      union foo { int i; double d; };
  218.      
  219.      union foo f = { d: 4 };
  220. will convert 4 to a `double' to store it in the union using the second
  221. element.  By contrast, casting 4 to type `union foo' would store it
  222. into the union as the integer `i', since it is an integer.  (*Note Cast
  223. to Union::.)
  224.    You can combine this technique of naming elements with ordinary C
  225. initialization of successive elements.  Each initializer element that
  226. does not have a label applies to the next consecutive element of the
  227. array or structure.  For example,
  228.      int a[6] = { [1] = v1, v2, [4] = v4 };
  229. is equivalent to
  230.      int a[6] = { 0, v1, v2, 0, v4, 0 };
  231.    Labeling the elements of an array initializer is especially useful
  232. when the indices are characters or belong to an `enum' type.  For
  233. example:
  234.      int whitespace[256]
  235.        = { [' '] = 1, ['\t'] = 1, ['\h'] = 1,
  236.            ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
  237. File: gcc.info,  Node: Case Ranges,  Next: Function Attributes,  Prev: Cast to Union,  Up: C Extensions
  238. Case Ranges
  239. ===========
  240.    You can specify a range of consecutive values in a single `case'
  241. label, like this:
  242.      case LOW ... HIGH:
  243. This has the same effect as the proper number of individual `case'
  244. labels, one for each integer value from LOW to HIGH, inclusive.
  245.    This feature is especially useful for ranges of ASCII character
  246. codes:
  247.      case 'A' ... 'Z':
  248.    *Be careful:* Write spaces around the `...', for otherwise it may be
  249. parsed wrong when you use it with integer values.  For example, write
  250. this:
  251.      case 1 ... 5:
  252. rather than this:
  253.      case 1...5:
  254. File: gcc.info,  Node: Cast to Union,  Next: Case Ranges,  Prev: Labeled Elements,  Up: C Extensions
  255. Cast to a Union Type
  256. ====================
  257.    A cast to union type is similar to other casts, except that the type
  258. specified is a union type.  You can specify the type either with `union
  259. TAG' or with a typedef name.  A cast to union is actually a constructor
  260. though, not a cast, and hence does not yield an lvalue like normal
  261. casts.  (*Note Constructors::.)
  262.    The types that may be cast to the union type are those of the members
  263. of the union.  Thus, given the following union and variables:
  264.      union foo { int i; double d; };
  265.      int x;
  266.      double y;
  267. both `x' and `y' can be cast to type `union' foo.
  268.    Using the cast as the right-hand side of an assignment to a variable
  269. of union type is equivalent to storing in a member of the union:
  270.      union foo u;
  271.      ...
  272.      u = (union foo) x  ==  u.i = x
  273.      u = (union foo) y  ==  u.d = y
  274.    You can also use the union cast as a function argument:
  275.      void hack (union foo);
  276.      ...
  277.      hack ((union foo) x);
  278. File: gcc.info,  Node: Function Attributes,  Next: Function Prototypes,  Prev: Case Ranges,  Up: C Extensions
  279. Declaring Attributes of Functions
  280. =================================
  281.    In GNU C, you declare certain things about functions called in your
  282. program which help the compiler optimize function calls and check your
  283. code more carefully.
  284.    The keyword `__attribute__' allows you to specify special attributes
  285. when making a declaration.  This keyword is followed by an attribute
  286. specification inside double parentheses.  Nine attributes, `noreturn',
  287. `const', `format', `no_instrument_function', `section', `constructor',
  288. `destructor', `unused' and `weak' are currently defined for functions.
  289. Other attributes, including `section' are supported for variables
  290. declarations (*note Variable Attributes::.) and for types (*note Type
  291. Attributes::.).
  292.    You may also specify attributes with `__' preceding and following
  293. each keyword.  This allows you to use them in header files without
  294. being concerned about a possible macro of the same name.  For example,
  295. you may use `__noreturn__' instead of `noreturn'.
  296. `noreturn'
  297.      A few standard library functions, such as `abort' and `exit',
  298.      cannot return.  GNU CC knows this automatically.  Some programs
  299.      define their own functions that never return.  You can declare them
  300.      `noreturn' to tell the compiler this fact.  For example,
  301.           void fatal () __attribute__ ((noreturn));
  302.           
  303.           void
  304.           fatal (...)
  305.           {
  306.             ... /* Print error message. */ ...
  307.             exit (1);
  308.           }
  309.      The `noreturn' keyword tells the compiler to assume that `fatal'
  310.      cannot return.  It can then optimize without regard to what would
  311.      happen if `fatal' ever did return.  This makes slightly better
  312.      code.  More importantly, it helps avoid spurious warnings of
  313.      uninitialized variables.
  314.      Do not assume that registers saved by the calling function are
  315.      restored before calling the `noreturn' function.
  316.      It does not make sense for a `noreturn' function to have a return
  317.      type other than `void'.
  318.      The attribute `noreturn' is not implemented in GNU C versions
  319.      earlier than 2.5.  An alternative way to declare that a function
  320.      does not return, which works in the current version and in some
  321.      older versions, is as follows:
  322.           typedef void voidfn ();
  323.           
  324.           volatile voidfn fatal;
  325. `const'
  326.      Many functions do not examine any values except their arguments,
  327.      and have no effects except the return value.  Such a function can
  328.      be subject to common subexpression elimination and loop
  329.      optimization just as an arithmetic operator would be.  These
  330.      functions should be declared with the attribute `const'.  For
  331.      example,
  332.           int square (int) __attribute__ ((const));
  333.      says that the hypothetical function `square' is safe to call fewer
  334.      times than the program says.
  335.      The attribute `const' is not implemented in GNU C versions earlier
  336.      than 2.5.  An alternative way to declare that a function has no
  337.      side effects, which works in the current version and in some older
  338.      versions, is as follows:
  339.           typedef int intfn ();
  340.           
  341.           extern const intfn square;
  342.      This approach does not work in GNU C++ from 2.6.0 on, since the
  343.      language specifies that the `const' must be attached to the return
  344.      value.
  345.      Note that a function that has pointer arguments and examines the
  346.      data pointed to must *not* be declared `const'.  Likewise, a
  347.      function that calls a non-`const' function usually must not be
  348.      `const'.  It does not make sense for a `const' function to return
  349.      `void'.
  350. `format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
  351.      The `format' attribute specifies that a function takes `printf',
  352.      `scanf', or `strftime' style arguments which should be type-checked
  353.      against a format string.  For example, the declaration:
  354.           extern int
  355.           my_printf (void *my_object, const char *my_format, ...)
  356.                 __attribute__ ((format (printf, 2, 3)));
  357.      causes the compiler to check the arguments in calls to `my_printf'
  358.      for consistency with the `printf' style format string argument
  359.      `my_format'.
  360.      The parameter ARCHETYPE determines how the format string is
  361.      interpreted, and should be either `printf', `scanf', or
  362.      `strftime'.  The parameter STRING-INDEX specifies which argument
  363.      is the format string argument (starting from 1), while
  364.      FIRST-TO-CHECK is the number of the first argument to check
  365.      against the format string.  For functions where the arguments are
  366.      not available to be checked (such as `vprintf'), specify the third
  367.      parameter as zero.  In this case the compiler only checks the
  368.      format string for consistency.
  369.      In the example above, the format string (`my_format') is the second
  370.      argument of the function `my_print', and the arguments to check
  371.      start with the third argument, so the correct parameters for the
  372.      format attribute are 2 and 3.
  373.      The `format' attribute allows you to identify your own functions
  374.      which take format strings as arguments, so that GNU CC can check
  375.      the calls to these functions for errors.  The compiler always
  376.      checks formats for the ANSI library functions `printf', `fprintf',
  377.      `sprintf', `scanf', `fscanf', `sscanf', `strftime', `vprintf',
  378.      `vfprintf' and `vsprintf' whenever such warnings are requested
  379.      (using `-Wformat'), so there is no need to modify the header file
  380.      `stdio.h'.
  381. `format_arg (STRING-INDEX)'
  382.      The `format_arg' attribute specifies that a function takes
  383.      `printf' or `scanf' style arguments, modifies it (for example, to
  384.      translate it into another language), and passes it to a `printf'
  385.      or `scanf' style function.  For example, the declaration:
  386.           extern char *
  387.           my_dgettext (char *my_domain, const char *my_format)
  388.                 __attribute__ ((format_arg (2)));
  389.      causes the compiler to check the arguments in calls to
  390.      `my_dgettext' whose result is passed to a `printf', `scanf', or
  391.      `strftime' type function for consistency with the `printf' style
  392.      format string argument `my_format'.
  393.      The parameter STRING-INDEX specifies which argument is the format
  394.      string argument (starting from 1).
  395.      The `format-arg' attribute allows you to identify your own
  396.      functions which modify format strings, so that GNU CC can check the
  397.      calls to `printf', `scanf', or `strftime' function whose operands
  398.      are a call to one of your own function.  The compiler always
  399.      treats `gettext', `dgettext', and `dcgettext' in this manner.
  400. `no_instrument_function'
  401.      If `-finstrument-functions' is given, profiling function calls will
  402.      be generated at entry and exit of most user-compiled functions.
  403.      Functions with this attribute will not be so instrumented.
  404. `section ("section-name")'
  405.      Normally, the compiler places the code it generates in the `text'
  406.      section.  Sometimes, however, you need additional sections, or you
  407.      need certain particular functions to appear in special sections.
  408.      The `section' attribute specifies that a function lives in a
  409.      particular section.  For example, the declaration:
  410.           extern void foobar (void) __attribute__ ((section ("bar")));
  411.      puts the function `foobar' in the `bar' section.
  412.      Some file formats do not support arbitrary sections so the
  413.      `section' attribute is not available on all platforms.  If you
  414.      need to map the entire contents of a module to a particular
  415.      section, consider using the facilities of the linker instead.
  416. `constructor'
  417. `destructor'
  418.      The `constructor' attribute causes the function to be called
  419.      automatically before execution enters `main ()'.  Similarly, the
  420.      `destructor' attribute causes the function to be called
  421.      automatically after `main ()' has completed or `exit ()' has been
  422.      called.  Functions with these attributes are useful for
  423.      initializing data that will be used implicitly during the
  424.      execution of the program.
  425.      These attributes are not currently implemented for Objective C.
  426. `unused'
  427.      This attribute, attached to a function, means that the function is
  428.      meant to be possibly unused.  GNU CC will not produce a warning
  429.      for this function.  GNU C++ does not currently support this
  430.      attribute as definitions without parameters are valid in C++.
  431. `weak'
  432.      The `weak' attribute causes the declaration to be emitted as a weak
  433.      symbol rather than a global.  This is primarily useful in defining
  434.      library functions which can be overridden in user code, though it
  435.      can also be used with non-function declarations.  Weak symbols are
  436.      supported for ELF targets, and also for a.out targets when using
  437.      the GNU assembler and linker.
  438. `alias ("target")'
  439.      The `alias' attribute causes the declaration to be emitted as an
  440.      alias for another symbol, which must be specified.  For instance,
  441.           void __f () { /* do something */; }
  442.           void f () __attribute__ ((weak, alias ("__f")));
  443.      declares `f' to be a weak alias for `__f'.  In C++, the mangled
  444.      name for the target must be used.
  445.      Not all target machines support this attribute.
  446. `no_check_memory_usage'
  447.      If `-fcheck-memory-usage' is given, calls to support routines will
  448.      be generated before most memory accesses, to permit support code to
  449.      record usage and detect uses of uninitialized or unallocated
  450.      storage.  Since the compiler cannot handle them properly, `asm'
  451.      statements are not allowed.  Declaring a function with this
  452.      attribute disables the memory checking code for that function,
  453.      permitting the use of `asm' statements without requiring separate
  454.      compilation with different options, and allowing you to write
  455.      support routines of your own if you wish, without getting infinite
  456.      recursion if they get compiled with this option.
  457. `regparm (NUMBER)'
  458.      On the Intel 386, the `regparm' attribute causes the compiler to
  459.      pass up to NUMBER integer arguments in registers EAX, EDX, and ECX
  460.      instead of on the stack.  Functions that take a variable number of
  461.      arguments will continue to be passed all of their arguments on the
  462.      stack.
  463. `stdcall'
  464.      On the Intel 386, the `stdcall' attribute causes the compiler to
  465.      assume that the called function will pop off the stack space used
  466.      to pass arguments, unless it takes a variable number of arguments.
  467.      The PowerPC compiler for Windows NT currently ignores the `stdcall'
  468.      attribute.
  469. `cdecl'
  470.      On the Intel 386, the `cdecl' attribute causes the compiler to
  471.      assume that the calling function will pop off the stack space used
  472.      to pass arguments.  This is useful to override the effects of the
  473.      `-mrtd' switch.
  474.      The PowerPC compiler for Windows NT currently ignores the `cdecl'
  475.      attribute.
  476. `longcall'
  477.      On the RS/6000 and PowerPC, the `longcall' attribute causes the
  478.      compiler to always call the function via a pointer, so that
  479.      functions which reside further than 64 megabytes (67,108,864
  480.      bytes) from the current location can be called.
  481. `dllimport'
  482.      On the PowerPC running Windows NT, the `dllimport' attribute causes
  483.      the compiler to call the function via a global pointer to the
  484.      function pointer that is set up by the Windows NT dll library.
  485.      The pointer name is formed by combining `__imp_' and the function
  486.      name.
  487. `dllexport'
  488.      On the PowerPC running Windows NT, the `dllexport' attribute causes
  489.      the compiler to provide a global pointer to the function pointer,
  490.      so that it can be called with the `dllimport' attribute.  The
  491.      pointer name is formed by combining `__imp_' and the function name.
  492. `exception (EXCEPT-FUNC [, EXCEPT-ARG])'
  493.      On the PowerPC running Windows NT, the `exception' attribute causes
  494.      the compiler to modify the structured exception table entry it
  495.      emits for the declared function.  The string or identifier
  496.      EXCEPT-FUNC is placed in the third entry of the structured
  497.      exception table.  It represents a function, which is called by the
  498.      exception handling mechanism if an exception occurs.  If it was
  499.      specified, the string or identifier EXCEPT-ARG is placed in the
  500.      fourth entry of the structured exception table.
  501. `function_vector'
  502.      Use this option on the H8/300 and H8/300H to indicate that the
  503.      specified function should be called through the function vector.
  504.      Calling a function through the function vector will reduce code
  505.      size, however; the function vector has a limited size (maximum 128
  506.      entries on the H8/300 and 64 entries on the H8/300H) and shares
  507.      space with the interrupt vector.
  508.      You must use GAS and GLD from GNU binutils version 2.7 or later for
  509.      this option to work correctly.
  510. `interrupt_handler'
  511.      Use this option on the H8/300 and H8/300H to indicate that the
  512.      specified function is an interrupt handler.  The compiler will
  513.      generate function entry and exit sequences suitable for use in an
  514.      interrupt handler when this attribute is present.
  515. `eightbit_data'
  516.      Use this option on the H8/300 and H8/300H to indicate that the
  517.      specified variable should be placed into the eight bit data
  518.      section.  The compiler will generate more efficient code for
  519.      certain operations on data in the eight bit data area.  Note the
  520.      eight bit data area is limited to 256 bytes of data.
  521.      You must use GAS and GLD from GNU binutils version 2.7 or later for
  522.      this option to work correctly.
  523. `tiny_data'
  524.      Use this option on the H8/300H to indicate that the specified
  525.      variable should be placed into the tiny data section.  The
  526.      compiler will generate more efficient code for loads and stores on
  527.      data in the tiny data section.  Note the tiny data area is limited
  528.      to slightly under 32kbytes of data.
  529. `interrupt'
  530.      Use this option on the M32R/D to indicate that the specified
  531.      function is an interrupt handler.  The compiler will generate
  532.      function entry and exit sequences suitable for use in an interrupt
  533.      handler when this attribute is present.
  534. `model (MODEL-NAME)'
  535.      Use this attribute on the M32R/D to set the addressability of an
  536.      object, and the code generated for a function.  The identifier
  537.      MODEL-NAME is one of `small', `medium', or `large', representing
  538.      each of the code models.
  539.      Small model objects live in the lower 16MB of memory (so that their
  540.      addresses can be loaded with the `ld24' instruction), and are
  541.      callable with the `bl' instruction.
  542.      Medium model objects may live anywhere in the 32 bit address space
  543.      (the compiler will generate `seth/add3' instructions to load their
  544.      addresses), and are callable with the `bl' instruction.
  545.      Large model objects may live anywhere in the 32 bit address space
  546.      (the compiler will generate `seth/add3' instructions to load their
  547.      addresses), and may not be reachable with the `bl' instruction
  548.      (the compiler will generate the much slower `seth/add3/jl'
  549.      instruction sequence).
  550.    You can specify multiple attributes in a declaration by separating
  551. them by commas within the double parentheses or by immediately
  552. following an attribute declaration with another attribute declaration.
  553.    Some people object to the `__attribute__' feature, suggesting that
  554. ANSI C's `#pragma' should be used instead.  There are two reasons for
  555. not doing this.
  556.   1. It is impossible to generate `#pragma' commands from a macro.
  557.   2. There is no telling what the same `#pragma' might mean in another
  558.      compiler.
  559.    These two reasons apply to almost any application that might be
  560. proposed for `#pragma'.  It is basically a mistake to use `#pragma' for
  561. *anything*.
  562. File: gcc.info,  Node: Function Prototypes,  Next: C++ Comments,  Prev: Function Attributes,  Up: C Extensions
  563. Prototypes and Old-Style Function Definitions
  564. =============================================
  565.    GNU C extends ANSI C to allow a function prototype to override a
  566. later old-style non-prototype definition.  Consider the following
  567. example:
  568.      /* Use prototypes unless the compiler is old-fashioned.  */
  569.      #ifdef __STDC__
  570.      #define P(x) x
  571.      #else
  572.      #define P(x) ()
  573.      #endif
  574.      
  575.      /* Prototype function declaration.  */
  576.      int isroot P((uid_t));
  577.      
  578.      /* Old-style function definition.  */
  579.      int
  580.      isroot (x)   /* ??? lossage here ??? */
  581.           uid_t x;
  582.      {
  583.        return x == 0;
  584.      }
  585.    Suppose the type `uid_t' happens to be `short'.  ANSI C does not
  586. allow this example, because subword arguments in old-style
  587. non-prototype definitions are promoted.  Therefore in this example the
  588. function definition's argument is really an `int', which does not match
  589. the prototype argument type of `short'.
  590.    This restriction of ANSI C makes it hard to write code that is
  591. portable to traditional C compilers, because the programmer does not
  592. know whether the `uid_t' type is `short', `int', or `long'.  Therefore,
  593. in cases like these GNU C allows a prototype to override a later
  594. old-style definition.  More precisely, in GNU C, a function prototype
  595. argument type overrides the argument type specified by a later
  596. old-style definition if the former type is the same as the latter type
  597. before promotion.  Thus in GNU C the above example is equivalent to the
  598. following:
  599.      int isroot (uid_t);
  600.      
  601.      int
  602.      isroot (uid_t x)
  603.      {
  604.        return x == 0;
  605.      }
  606.    GNU C++ does not support old-style function definitions, so this
  607. extension is irrelevant.
  608. File: gcc.info,  Node: C++ Comments,  Next: Dollar Signs,  Prev: Function Prototypes,  Up: C Extensions
  609. C++ Style Comments
  610. ==================
  611.    In GNU C, you may use C++ style comments, which start with `//' and
  612. continue until the end of the line.  Many other C implementations allow
  613. such comments, and they are likely to be in a future C standard.
  614. However, C++ style comments are not recognized if you specify `-ansi'
  615. or `-traditional', since they are incompatible with traditional
  616. constructs like `dividend//*comment*/divisor'.
  617. File: gcc.info,  Node: Dollar Signs,  Next: Character Escapes,  Prev: C++ Comments,  Up: C Extensions
  618. Dollar Signs in Identifier Names
  619. ================================
  620.    In GNU C, you may normally use dollar signs in identifier names.
  621. This is because many traditional C implementations allow such
  622. identifiers.  However, dollar signs in identifiers are not supported on
  623. a few target machines, typically because the target assembler does not
  624. allow them.
  625. File: gcc.info,  Node: Character Escapes,  Next: Variable Attributes,  Prev: Dollar Signs,  Up: C Extensions
  626. The Character <ESC> in Constants
  627. ================================
  628.    You can use the sequence `\e' in a string or character constant to
  629. stand for the ASCII character <ESC>.
  630. File: gcc.info,  Node: Alignment,  Next: Inline,  Prev: Type Attributes,  Up: C Extensions
  631. Inquiring on Alignment of Types or Variables
  632. ============================================
  633.    The keyword `__alignof__' allows you to inquire about how an object
  634. is aligned, or the minimum alignment usually required by a type.  Its
  635. syntax is just like `sizeof'.
  636.    For example, if the target machine requires a `double' value to be
  637. aligned on an 8-byte boundary, then `__alignof__ (double)' is 8.  This
  638. is true on many RISC machines.  On more traditional machine designs,
  639. `__alignof__ (double)' is 4 or even 2.
  640.    Some machines never actually require alignment; they allow reference
  641. to any data type even at an odd addresses.  For these machines,
  642. `__alignof__' reports the *recommended* alignment of a type.
  643.    When the operand of `__alignof__' is an lvalue rather than a type,
  644. the value is the largest alignment that the lvalue is known to have.
  645. It may have this alignment as a result of its data type, or because it
  646. is part of a structure and inherits alignment from that structure.  For
  647. example, after this declaration:
  648.      struct foo { int x; char y; } foo1;
  649. the value of `__alignof__ (foo1.y)' is probably 2 or 4, the same as
  650. `__alignof__ (int)', even though the data type of `foo1.y' does not
  651. itself demand any alignment.
  652.    A related feature which lets you specify the alignment of an object
  653. is `__attribute__ ((aligned (ALIGNMENT)))'; see the following section.
  654. File: gcc.info,  Node: Variable Attributes,  Next: Type Attributes,  Prev: Character Escapes,  Up: C Extensions
  655. Specifying Attributes of Variables
  656. ==================================
  657.    The keyword `__attribute__' allows you to specify special attributes
  658. of variables or structure fields.  This keyword is followed by an
  659. attribute specification inside double parentheses.  Eight attributes
  660. are currently defined for variables: `aligned', `mode', `nocommon',
  661. `packed', `section', `transparent_union', `unused', and `weak'.  Other
  662. attributes are available for functions (*note Function Attributes::.)
  663. and for types (*note Type Attributes::.).
  664.    You may also specify attributes with `__' preceding and following
  665. each keyword.  This allows you to use them in header files without
  666. being concerned about a possible macro of the same name.  For example,
  667. you may use `__aligned__' instead of `aligned'.
  668. `aligned (ALIGNMENT)'
  669.      This attribute specifies a minimum alignment for the variable or
  670.      structure field, measured in bytes.  For example, the declaration:
  671.           int x __attribute__ ((aligned (16))) = 0;
  672.      causes the compiler to allocate the global variable `x' on a
  673.      16-byte boundary.  On a 68040, this could be used in conjunction
  674.      with an `asm' expression to access the `move16' instruction which
  675.      requires 16-byte aligned operands.
  676.      You can also specify the alignment of structure fields.  For
  677.      example, to create a double-word aligned `int' pair, you could
  678.      write:
  679.           struct foo { int x[2] __attribute__ ((aligned (8))); };
  680.      This is an alternative to creating a union with a `double' member
  681.      that forces the union to be double-word aligned.
  682.      It is not possible to specify the alignment of functions; the
  683.      alignment of functions is determined by the machine's requirements
  684.      and cannot be changed.  You cannot specify alignment for a typedef
  685.      name because such a name is just an alias, not a distinct type.
  686.      As in the preceding examples, you can explicitly specify the
  687.      alignment (in bytes) that you wish the compiler to use for a given
  688.      variable or structure field.  Alternatively, you can leave out the
  689.      alignment factor and just ask the compiler to align a variable or
  690.      field to the maximum useful alignment for the target machine you
  691.      are compiling for.  For example, you could write:
  692.           short array[3] __attribute__ ((aligned));
  693.      Whenever you leave out the alignment factor in an `aligned'
  694.      attribute specification, the compiler automatically sets the
  695.      alignment for the declared variable or field to the largest
  696.      alignment which is ever used for any data type on the target
  697.      machine you are compiling for.  Doing this can often make copy
  698.      operations more efficient, because the compiler can use whatever
  699.      instructions copy the biggest chunks of memory when performing
  700.      copies to or from the variables or fields that you have aligned
  701.      this way.
  702.      The `aligned' attribute can only increase the alignment; but you
  703.      can decrease it by specifying `packed' as well.  See below.
  704.      Note that the effectiveness of `aligned' attributes may be limited
  705.      by inherent limitations in your linker.  On many systems, the
  706.      linker is only able to arrange for variables to be aligned up to a
  707.      certain maximum alignment.  (For some linkers, the maximum
  708.      supported alignment may be very very small.)  If your linker is
  709.      only able to align variables up to a maximum of 8 byte alignment,
  710.      then specifying `aligned(16)' in an `__attribute__' will still
  711.      only provide you with 8 byte alignment.  See your linker
  712.      documentation for further information.
  713. `mode (MODE)'
  714.      This attribute specifies the data type for the
  715.      declaration--whichever type corresponds to the mode MODE.  This in
  716.      effect lets you request an integer or floating point type
  717.      according to its width.
  718.      You may also specify a mode of `byte' or `__byte__' to indicate
  719.      the mode corresponding to a one-byte integer, `word' or `__word__'
  720.      for the mode of a one-word integer, and `pointer' or `__pointer__'
  721.      for the mode used to represent pointers.
  722. `nocommon'
  723.      This attribute specifies requests GNU CC not to place a variable
  724.      "common" but instead to allocate space for it directly.  If you
  725.      specify the `-fno-common' flag, GNU CC will do this for all
  726.      variables.
  727.      Specifying the `nocommon' attribute for a variable provides an
  728.      initialization of zeros.  A variable may only be initialized in one
  729.      source file.
  730. `packed'
  731.      The `packed' attribute specifies that a variable or structure field
  732.      should have the smallest possible alignment--one byte for a
  733.      variable, and one bit for a field, unless you specify a larger
  734.      value with the `aligned' attribute.
  735.      Here is a structure in which the field `x' is packed, so that it
  736.      immediately follows `a':
  737.           struct foo
  738.           {
  739.             char a;
  740.             int x[2] __attribute__ ((packed));
  741.           };
  742. `section ("section-name")'
  743.      Normally, the compiler places the objects it generates in sections
  744.      like `data' and `bss'.  Sometimes, however, you need additional
  745.      sections, or you need certain particular variables to appear in
  746.      special sections, for example to map to special hardware.  The
  747.      `section' attribute specifies that a variable (or function) lives
  748.      in a particular section.  For example, this small program uses
  749.      several specific section names:
  750.           struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
  751.           struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
  752.           char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
  753.           int init_data __attribute__ ((section ("INITDATA"))) = 0;
  754.           
  755.           main()
  756.           {
  757.             /* Initialize stack pointer */
  758.             init_sp (stack + sizeof (stack));
  759.           
  760.             /* Initialize initialized data */
  761.             memcpy (&init_data, &data, &edata - &data);
  762.           
  763.             /* Turn on the serial ports */
  764.             init_duart (&a);
  765.             init_duart (&b);
  766.           }
  767.      Use the `section' attribute with an *initialized* definition of a
  768.      *global* variable, as shown in the example.  GNU CC issues a
  769.      warning and otherwise ignores the `section' attribute in
  770.      uninitialized variable declarations.
  771.      You may only use the `section' attribute with a fully initialized
  772.      global definition because of the way linkers work.  The linker
  773.      requires each object be defined once, with the exception that
  774.      uninitialized variables tentatively go in the `common' (or `bss')
  775.      section and can be multiply "defined".  You can force a variable
  776.      to be initialized with the `-fno-common' flag or the `nocommon'
  777.      attribute.
  778.      Some file formats do not support arbitrary sections so the
  779.      `section' attribute is not available on all platforms.  If you
  780.      need to map the entire contents of a module to a particular
  781.      section, consider using the facilities of the linker instead.
  782. `transparent_union'
  783.      This attribute, attached to a function parameter which is a union,
  784.      means that the corresponding argument may have the type of any
  785.      union member, but the argument is passed as if its type were that
  786.      of the first union member.  For more details see *Note Type
  787.      Attributes::.  You can also use this attribute on a `typedef' for
  788.      a union data type; then it applies to all function parameters with
  789.      that type.
  790. `unused'
  791.      This attribute, attached to a variable, means that the variable is
  792.      meant to be possibly unused.  GNU CC will not produce a warning
  793.      for this variable.
  794. `weak'
  795.      The `weak' attribute is described in *Note Function Attributes::.
  796. `model (MODEL-NAME)'
  797.      Use this attribute on the M32R/D to set the addressability of an
  798.      object.  The identifier MODEL-NAME is one of `small', `medium', or
  799.      `large', representing each of the code models.
  800.      Small model objects live in the lower 16MB of memory (so that their
  801.      addresses can be loaded with the `ld24' instruction).
  802.      Medium and large model objects may live anywhere in the 32 bit
  803.      address space (the compiler will generate `seth/add3' instructions
  804.      to load their addresses).
  805.    To specify multiple attributes, separate them by commas within the
  806. double parentheses: for example, `__attribute__ ((aligned (16),
  807. packed))'.
  808.